<?php

class Controller_User_Login extends Controller
{
	function execute($request)
	{
		$form = new Form_User_Login();

		if ($request -> isPost() && $form -> isValid($_POST))
		{
			$values = $form -> getValues();

			$user = Model::factory('user');

			$user -> load(array('email' => $values['email']));

			if ($user -> isMember())
			{

				/**
				 * pass valiate password
				 */
				if ($user -> isValidPassword($values['password']))
				{
					$_SESSION['user_id'] = $user -> getId();
					$this->redirect('/agilet/home');
				}
			}
		}
		$request -> response = View::render(array('form' => $form), 'user/login');
	}

}
